package com.briup.mt.service.impl;

import com.briup.mt.bean.Application;
import com.briup.mt.bean.ApplicationExample;
import com.briup.mt.dao.ApplicationMapper;
import com.briup.mt.service.IApplicationService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
@Service
public class ApplicationImpl implements IApplicationService {

    @Resource
    private ApplicationMapper applicationMapper;

    @Override
    public List<Application> query(String name,String telephone) {
        ApplicationExample example = new ApplicationExample();

        if(!StringUtils.isEmpty(name)){
            example.createCriteria().andNameLike("%"+name+"%");
        }

        if(!StringUtils.isEmpty(telephone)){
            example.createCriteria().andTelephoneLike("%"+telephone+"%");
        }


        List<Application> list = applicationMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(Application application) {
        if (application.getId()==null){
            applicationMapper.insert(application);
        }else{
            applicationMapper.updateByPrimaryKey(application);
        }

    }

    @Override
    public void deleteById(long id) {
        applicationMapper.deleteByPrimaryKey(id);
    }
}
